package cn.com.dpc;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.GridView;
import android.widget.ImageButton;
import cn.com.dpc.adapter.ImageAdapter;
import cn.com.dpc.setActivity.AlarmLevelSetActivity;
import cn.com.dpc.setActivity.AlarmSoundSetActivity;
import cn.com.dpc.setActivity.MoreSetActivity;
import cn.com.dpc.setActivity.UpdateActivity;

public class AddActivity extends Activity {
	private ImageAdapter ia = null;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.add);

		GridView gridview = (GridView) findViewById(R.id.GridView);

		// 添加Item到网格中
		ia = new ImageAdapter(this);
		gridview.setAdapter(ia);
		gridview.setOnItemClickListener(new OnItemClickListener() {
			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1,
					int position, long arg3) {
				String clickStr = ia.className[position];
				if (clickStr.equals("alarmSoundSet")) {
					Intent intent = new Intent(AddActivity.this,
							AlarmSoundSetActivity.class);
					intent.setFlags(1);
					startActivity(intent);
				}
				if (clickStr.equals("alarmLevelSet")) {
					Intent intent = new Intent(AddActivity.this,
							AlarmLevelSetActivity.class);
					intent.setFlags(1);
					startActivity(intent);
				}
				if (clickStr.equals("moreSet")) {
					Intent intent = new Intent(AddActivity.this,
							MoreSetActivity.class);
					intent.setFlags(1);
					startActivity(intent);
				}
				if (clickStr.equals("update")) {
					Intent intent = new Intent(AddActivity.this,
							UpdateActivity.class);
					intent.setFlags(1);
					startActivity(intent);
				}
				if (clickStr.equals("about")) {
					Intent intent = new Intent(AddActivity.this,
							AboutActivity.class);
					intent.setFlags(1);
					startActivity(intent);
				}
			}
		});

		// 隐藏按钮
		ImageButton editButton = (ImageButton) findViewById(R.id.edit_button);
		editButton.setVisibility(View.INVISIBLE);
		ImageButton backButton = (ImageButton) findViewById(R.id.back_button);
		backButton.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				AddActivity.this.finish();
			}
		});
	}

	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
			return false;
		}
		return false;
	}
}
